import json
import time
import os
import unittest
import requests
from selenium.webdriver.firefox.options import Options as FOptions
from selenium.webdriver.chrome.options import Options as Foptions
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

options = FOptions()
browser = webdriver.Firefox(executable_path="D:/geckodriver.exe",firefox_options=options)

# selenium 获取cookies
# browser.get('https://login.taobao.com/member/login.jhtml?redirectURL=http%3A%2F%2Fbuyertrade.taobao.com%2Ftrade%2Fitemlist%2Flist_bought_items.htm%3Fspm%3D875.7931836%252FB.a2226mz.4.66144265Vdg7d5%26t%3D20110530')
# input()
# dictCookies = browser.get_cookies()
# jsonCookies = json.dumps(dictCookies)
# with open('cookies.json','w') as f:
#     f.write(jsonCookies)

# 初次建立连接，随后方可修改cookie
browser.get('http://h5.waimai.meituan.com/')

button = browser.find_element_by_class_name("_3_juUbSw5kiHB8btC6rFF6 lazyimage-holder")
button.click()
































# 删除第一次建立连接时的cookie
# browser.delete_all_cookies()
# # 读取登录室存储到本地的cookie
# with open('cookies.json','r') as f:
#     listCookies = json.loads(f.read())
#
# for cookie in listCookies:
#     browser.add_cookie({
#         'domain':'.taobao.com',  #此处xxx.com前，需要带点
#         'name':cookie['name'],
#         'value':cookie['value'],
#         'path':'/',
#         'expires':None
#     })
# # 再次访问页面，便可实现免登录页面
# browser.get('https://www.taobao.com')



url = 'http://i.waimai.meituan.com/openh5/poi/comments?_=1547643919664'

headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
            'Cookie': '_lx_utm=utm_source%3DBaidu%26utm_medium%3Dorganic; _lxsdk_cuid=1683b4952efc8-0d7dc62d5d7279-50432518-144000-1683b4952f0c8; _lxsdk=1683b4952efc8-0d7dc62d5d7279-50432518-144000-1683b4952f0c8; terminal=i; w_utmz="utm_campaign=(direct)&utm_source=5000&utm_medium=(none)&utm_content=(none)&utm_term=(none)"; w_uuid=lwH6-3a0tlcwaSESYwlq2i0SN8B3VCFwzEKyuJnZrU7xwgKZ7xOq14HdE-l75X3s; uuid=3123c06438604c2eaf75.1547183015.1.0.0; mtcdn=K; lsu=; __mta=142391181.1547182892013.1547182892013.1547192943315.2; _ga=GA1.3.770960937.1547193330; w_latlng=0,0; w_actual_lat=34721175; w_actual_lng=113651155; wm_order_channel=default; openh5_uuid=; w_visitid=009ef484-dbe9-49d0-b398-054098edfc3f; openh5_uuid=sloNlLGcu8NXbxWxjo68jEdQRquM4ZBhYwNI7_6wTpTyeD8L20xIRJ5Sbi8YPgaz; _lxsdk_s=16856c251e1-f71-d8b-437%7C%7C5'

}

result = requests.get(url=url,headers=headers)
print(result.text)